/* This program produces the parts of Table 1 that use administrative data 
- The table has to be assembled manually */

***** Set directories 
local dir_raw 		"~/Dropbox/Retirement gaming/raw"
local dir_clean 	"~/Dropbox/Retirement gaming/clean"
local dir_output 	"~/Dropbox/Retirement gaming/output/dataverse"


use "`dir_clean'/mainsample_age50analysis.dta", clear

g repdens=prop_mself if self_empl==1
replace repdens=prop_mempl if empl==1

local outcomelist1 = " W Wficto reports_ficto repdens "
local outcomelist2 = " W repdens "
local controlslist1 = "age noempl micro micro2 larger "
local controlslist2 = "manufacturing retailhospitality transportenergy services "

label var W 			"Reported earnings (1000 UY\$)" 
label var Wficto 		"Reported earnings/MCB" 
label var reports_ficto	"Reported earnings = MCB"
label var repdens 		"Reporting density"
label var hrsweek		"Hours of work/week"
label var age			"Age"
label var noempl 		"Firm with 0 employees"
label var micro 		"Firm with 1-4 employees"
label var micro2 		"Firm with 5-9 employees"
label var larger		"Firm with 10+ employees"
label var manufacturing 	"Manufacturing"
label var retailhospitality "Retail, Hospitality"
label var transportenergy 	"Transp., Comm., Energy"
label var services			"Services, Other"


estimates clear
*All self-empl
eststo: quietly estpost summarize `outcomelist1' `controlslist1' `controlslist2' if self_empl==1, casewise esample
	cap drop aux
	egen aux= group(i) if  e(sample)==1
	sum aux 
	estadd scalar Indiv=r(max)
	drop aux
*All employees
eststo: quietly estpost summarize `outcomelist2' `controlslist1' `controlslist2' if empl==1 , casewise esample
	egen aux= group(i) if  e(sample)==1
	sum aux 
	estadd scalar Indiv=r(max)
	drop aux
esttab using "`dir_output'/table1_admin.tex", replace ///
	cells("mean(fmt(2)) sd(fmt(2) par)")  nostar nonote label nonumber nodepvar ///
	mtitles("Self-Empl" "All Empl" ) ///
	style(tex) f nogaps scalars(N Indiv)
* Add hours of work  
estimates clear
eststo: quietly estpost summarize hrsweek if self_empl==1 & prop_mself_empl>=0, casewise 
eststo: quietly estpost summarize hrsweek if empl==1 & prop_mempl>=0, casewise 
esttab using "`dir_output'/table1_admin.tex", append ///
	cells("mean(fmt(2)) sd(fmt(2) par)")  nostar nonote label nonumber nodepvar ///
	style(tex) f nogaps nomtitles scalars(N)
*Employees small firms
estimates clear
eststo: quietly estpost summarize W if empl==1 & large_1stobs==0, casewise esample
	egen aux= group(i) if  e(sample)==1
	sum aux 
	estadd scalar Indiv=r(max)
	drop aux
esttab using "`dir_output'/table1_admin_small.tex", replace ///
	cells("mean(fmt(2)) sd(fmt(2) par)")  nostar nonote label nonumber nodepvar ///
	style(tex) f nogaps nomtitles scalars(N Indiv)
clear
